{extend name="public:layout" /}

{block name="title"}
	<title>{:site('siteName')}-我的账户</title>
{/block}

{block name="css"}
	<link rel="stylesheet" type="text/css" href="__STATIC__/{$theme}/css/user.css">
{/block}

{block name="content"}
	<div class="layui-main">
		<div class="user-main">
			<div class="user-left">
				{include file="public:user" index="4" /}
			</div>
			<div class="user-right">
				<div class="layui-tab layui-tab-brief">
					<ul class="layui-tab-title" style="float: left;">
						<li class="layui-this">我的账户</li>
					</ul>
					<form class="layui-form" style="float: right;margin-top: 10px;">
						<div class="layui-form-item">
							<div class="layui-input-inline">
								<select name="onekey" lay-filter="onekey">
									<option value="0">一键收豆助手</option>
								  	<option value="1">收推荐奖为{:config("currency")["money"]}</option>
								  	<option value="2">收推荐奖为{:config("currency")["recharge"]}</option>
								  	<option value="3">收分红奖为{:config("currency")["money"]}</option>
								  	<option value="4">收分红奖为{:config("currency")["recharge"]}</option>
								</select>
							</div>
						</div>
					</form>
					<div class="layui-tab-content">

						<table class="table">
						    <thead>
						        <tr>
						            <th width="150">账户名</th>
						            <!-- <th>激活价</th>
						            <th>分红天数</th> -->
						            <th>推荐奖</th>
						            <th>每日分红</th>
						            <th>累计分红</th>
						            <th>剩余分红</th>
						            <th>激活时间</th>
						            <th>状态</th>
						            <th>操作</th>
						        </tr>
						    </thead>
						    <tbody>
								{volist name="accounts" id="v"}
						        <tr>
						        	<td>{$v.name}</td>
						        	<!-- <td>{$v.price}</td>
						        	<td>{$v.day}</td> -->
						        	<td>{$v.invite}</td>
						            <td>{$v.money}</td>
						            <td>{$v.total}</td>
						            <td>{$v.balance}</td>
						            <td>{$v['time'] ? date('Y-m-d',$v['time']) : ''}</td>
						            <td>
						            	{eq name="v.status" value="0"}未激活{/eq}
						            	{eq name="v.status" value="1"}分红中{/eq}
						            	{eq name="v.status" value="2"}已出局{/eq}
						            </td>
						            <td>
						            	{eq name="v.status" value="0"}
						            		<button class="layui-btn layui-btn-mini layui-btn-main confirm_pwd active_confirm" aid="{$v.id}">激活</button>
						            	{/eq}
						            	{gt name="v.status" value="0"}
						            		<button class="layui-btn layui-btn-mini layui-btn-red get_money" main_id="{$v.id}">收{:config("currency")["money"]}</button>
						            		<button class="layui-btn layui-btn-mini layui-btn-warm get_recharge" main_id="{$v.id}">收{:config("currency")["recharge"]}</button>
						            	{/gt}	
						            </td>
						        </tr>
								{/volist}
						    </tbody>
						</table>
						<div class="page">
							{$accounts->render()}
						</div>
					</div>
				</div> 
			</div>
		</div>
	</div>
{/block}

{block name="script"}
	<script type="text/javascript">
		layui.use(['form', 'layer'], function(){
			var $ = layui.jquery;
    		var layer = layui.layer;
    		var form = layui.form();
    		//激活
    		$(".active_confirm").click(function() {
    			var aid = $(this).attr('aid');
	    		var msg = '激活此账户需要'+ '{:config("abonus")["main_price"]}' +'个'+ '{:config("currency")["recharge"]}' +'，确定？';
    			checkPwd(function(pwd){
			        layer.confirm(msg, {
			            btn: ['激活', '取消'],
			            icon: 3
			        }, function(index) {
			            layer.close(index);
			            $.post('{:url("index/account/index")}', {id: aid,pwd:pwd}, function(res) {
			            	if(res.status == 1){
			            		layer.msg(res.msg, {
				                    time: 1000
				                }, function() {
				                    location.reload();
				                });
			            	}else{
			            		layer.msg(res.msg);
			            	}
			            });
			        });
    			});
		        return false;
		    });

    		//收分红币
    		$('.get_money').click(function(){
    			var main_id = $(this).attr('main_id');
    			var full_money = '{:config("abonus")["full_money"]}';
    			checkPwd(function(pwd){
    				layer.prompt({
					  	title: '请输入要收的数量，不能低于'+full_money+'个',
					}, function(num, index, elem){
						if(!/^\+?[1-9][0-9]*$/.test(num)){
							layer.msg('请输入一个正整数');
							return;
						}
						if(num < full_money){
							layer.msg('数量不能低于'+full_money+'个');
							return;
						}
					  	$.post("{:url('index/account/getMoney')}", {id: main_id,num:num,pwd:pwd,type:1}, function(res) {
			            	if(res.success == 1){
			            		layer.close(index);
			            		layer.msg(res.msg, {time: 1000}, function() {
				                	location.reload();
				                });
			            	}else{
			            		layer.msg(res.msg);
			            	}
			            },'json');
					});
    			});
    			return false;
    		});

    		//收充值币
    		$('.get_recharge').click(function(){
    			var main_id = $(this).attr('main_id');
    			var full_recharge = '{:config("abonus")["full_recharge"]}';
    			checkPwd(function(pwd){
    				layer.prompt({
					  	title: '请输入要收的数量，不能低于'+full_recharge+'个',
					}, function(num, index, elem){
						if(!/^\+?[1-9][0-9]*$/.test(num)){
							layer.msg('请输入一个正整数');
							return;
						}
						if(num < full_recharge){
							layer.msg('数量不能低于'+full_recharge+'个');
							return;
						}
					  	$.post("{:url('index/account/getRecharge')}", {id: main_id,num:num,pwd:pwd,type:1}, function(res) {
			            	if(res.success == 1){
			            		layer.close(index);
			            		layer.msg(res.msg, {time: 1000}, function() {
				                	location.reload();
				                });
			            	}else{
			            		layer.msg(res.msg);
			            	}
			            },'json');
					});
    			});
    			return false;
    		});
    		//一键收豆
    		form.on('select(onekey)', function(data){
    			if(data.value > 0){
    				checkPwd(function(pwd){
					  	$.post("{:url('index/account/onekey')}", {type: data.value,pwd:pwd,diff:1}, function(res) {
			            	if(res.success == 1){
			            		layer.msg(res.msg, {time: 1000}, function() {
				                	location.reload();
				                });
			            	}else{
			            		layer.msg(res.msg);
			            	}
			            },'json');
	    			});
    			}
    			return false;
			});
		});
	</script>
{/block}